package aml.bs.commons;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Title: CollectionUtil
 * @Author duxuqiang02
 * @Date 2023/9/17 12:29
 * @description: 集合操作工具类
 */
public class CollectionUtil {

    /**
     * 无法add null元素
     * @param collection
     * @return
     * @param <T>
     */
    public static <T> List<T> addItemWithoutNull(Collection<T> collection){
        if (collection.isEmpty()){
            return (List<T>) CollectionUtils.emptyCollection();
        }
        CollectionUtils.addIgnoreNull(collection,null);
        return (List<T>) collection;
    }

    /**
     * 收集多个List 变为一个
     *
     * @param array
     * @param arrayExpand
     * @param <T>
     * @return
     */
    public static<T> List<T> collectArray(List<T> array , List<T> arrayExpand){
        if (array.isEmpty()){
            return new ArrayList<>();
        }

        return Stream.of(array, arrayExpand).flatMap(Collection::stream).collect(Collectors.toList());
    }
}
